Index: file.c =================================================================== RCS file: /usr/cvsroot/asterisk/file.c,v retrieving revision 1.39 diff -u -r1.39 file.c --- file.c 6 Apr 2004 22:17:31 -0000 1.39 +++ file.c 10 Apr 2004 18:32:06 -0000 @@ -27,6 +27,7 @@ #include #include #include +#include #include #include "asterisk.h" #include "astconf.h" @@ -56,6 +57,8 @@ struct ast_frame * (*read)(struct ast_filestream *, int *whennext); /* Close file, and destroy filestream structure */ void (*close)(struct ast_filestream *); + /* Retrieve file length (in samples) */ + long (*length)(struct ast_filestream *); /* Retrieve file comment */ char * (*getcomment)(struct ast_filestream *); /* Link */ @@ -91,6 +94,7 @@ long (*tell)(struct ast_filestream *), struct ast_frame * (*read)(struct ast_filestream *, int *whennext), void (*close)(struct ast_filestream *), + long (*length)(struct ast_filestream *), char * (*getcomment)(struct ast_filestream *)) { struct ast_format *tmp; @@ -124,6 +128,7 @@ tmp->tell = tell; tmp->close = close; tmp->format = format; + tmp->length = length; tmp->getcomment = getcomment; tmp->next = formats; formats = tmp; @@ -621,6 +634,17 @@ return fs->fmt->tell(fs); } +long ast_lengthfile(struct ast_channel *chan, char *filename, char *preflang) +{ + struct ast_filestream *fs; + + fs = ast_openstream(chan, filename, preflang); + if (fs && fs->fmt->length) + return fs->fmt->length(fs); + else + return -1; +} + int ast_stream_fastforward(struct ast_filestream *fs, long ms) { /* I think this is right, 8000 samples per second, 1000 ms a second so 8 Index: formats/format_g723.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_g723.c,v retrieving revision 1.12 diff -u -r1.12 format_g723.c --- formats/format_g723.c 25 Feb 2004 22:31:51 -0000 1.12 +++ formats/format_g723.c 10 Apr 2004 18:32:11 -0000 @@ -327,6 +327,7 @@ g723_tell, g723_read, g723_close, + NULL, g723_getcomment); Index: formats/format_g726.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_g726.c,v retrieving revision 1.1 diff -u -r1.1 format_g726.c --- formats/format_g726.c 27 Feb 2004 05:16:26 -0000 1.1 +++ formats/format_g726.c 10 Apr 2004 18:32:11 -0000 @@ -403,6 +403,7 @@ g726_tell, g726_read, g726_close, + NULL, g726_getcomment); if (res) { ast_log(LOG_WARNING, "Failed to register format %s.\n", name40); @@ -417,6 +418,7 @@ g726_tell, g726_read, g726_close, + NULL, g726_getcomment); if (res) { ast_log(LOG_WARNING, "Failed to register format %s.\n", name32); @@ -431,6 +433,7 @@ g726_tell, g726_read, g726_close, + NULL, g726_getcomment); if (res) { ast_log(LOG_WARNING, "Failed to register format %s.\n", name24); @@ -445,6 +448,7 @@ g726_tell, g726_read, g726_close, + NULL, g726_getcomment); if (res) { ast_log(LOG_WARNING, "Failed to register format %s.\n", name16); Index: formats/format_g729.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_g729.c,v retrieving revision 1.9 diff -u -r1.9 format_g729.c --- formats/format_g729.c 28 Jan 2004 21:32:48 -0000 1.9 +++ formats/format_g729.c 10 Apr 2004 18:32:11 -0000 @@ -216,6 +216,7 @@ g729_tell, g729_read, g729_close, + NULL, g729_getcomment); Index: formats/format_gsm.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_gsm.c,v retrieving revision 1.14 diff -u -r1.14 format_gsm.c --- formats/format_gsm.c 3 Feb 2004 16:57:00 -0000 1.14 +++ formats/format_gsm.c 10 Apr 2004 18:32:11 -0000 @@ -222,6 +222,15 @@ return (offset/33)*160; } +static long gsm_length(struct ast_filestream *fs) +{ + long offset, size; + offset = lseek(fs->fd, 0, SEEK_CUR); + size = lseek(fs->fd, 0, SEEK_END); + lseek(fs->fd, offset, SEEK_SET); + return (size*160)/33; +} + static char *gsm_getcomment(struct ast_filestream *s) { return NULL; @@ -238,6 +247,7 @@ gsm_tell, gsm_read, gsm_close, + gsm_length, gsm_getcomment); Index: formats/format_h263.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_h263.c,v retrieving revision 1.4 diff -u -r1.4 format_h263.c --- formats/format_h263.c 22 Jan 2004 21:30:04 -0000 1.4 +++ formats/format_h263.c 10 Apr 2004 18:32:11 -0000 @@ -238,6 +238,7 @@ h263_tell, h263_read, h263_close, + NULL, h263_getcomment); Index: formats/format_pcm.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_pcm.c,v retrieving revision 1.10 diff -u -r1.10 format_pcm.c --- formats/format_pcm.c 8 Sep 2003 16:48:07 -0000 1.10 +++ formats/format_pcm.c 10 Apr 2004 18:32:11 -0000 @@ -189,6 +189,15 @@ return offset; } +static long pcm_length(struct ast_filestream *fs) +{ + long offset, size; + offset = lseek(fs->fd, 0, SEEK_CUR); + size = lseek(fs->fd, 0, SEEK_END); + lseek(fs->fd, offset, SEEK_SET); + return size; +} + static char *pcm_getcomment(struct ast_filestream *s) { return NULL; @@ -205,6 +214,7 @@ pcm_tell, pcm_read, pcm_close, + pcm_length, pcm_getcomment); Index: formats/format_pcm_alaw.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_pcm_alaw.c,v retrieving revision 1.9 diff -u -r1.9 format_pcm_alaw.c --- formats/format_pcm_alaw.c 28 Jan 2004 21:06:03 -0000 1.9 +++ formats/format_pcm_alaw.c 10 Apr 2004 18:32:11 -0000 @@ -287,6 +287,7 @@ pcm_tell, pcm_read, pcm_close, + NULL, pcm_getcomment); } Index: formats/format_vox.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_vox.c,v retrieving revision 1.13 diff -u -r1.13 format_vox.c --- formats/format_vox.c 11 Mar 2004 19:57:10 -0000 1.13 +++ formats/format_vox.c 10 Apr 2004 18:32:11 -0000 @@ -191,6 +191,7 @@ vox_tell, vox_read, vox_close, + NULL, vox_getcomment); Index: formats/format_wav.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_wav.c,v retrieving revision 1.15 diff -u -r1.15 format_wav.c --- formats/format_wav.c 2 Feb 2004 06:34:27 -0000 1.15 +++ formats/format_wav.c 10 Apr 2004 18:32:11 -0000 @@ -561,6 +561,7 @@ wav_tell, wav_read, wav_close, + NULL, wav_getcomment); Index: formats/format_wav_gsm.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_wav_gsm.c,v retrieving revision 1.18 diff -u -r1.18 format_wav_gsm.c --- formats/format_wav_gsm.c 26 Feb 2004 06:46:01 -0000 1.18 +++ formats/format_wav_gsm.c 10 Apr 2004 18:32:11 -0000 @@ -539,6 +539,7 @@ wav_tell, wav_read, wav_close, + NULL, wav_getcomment); Index: include/asterisk/file.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/file.h,v retrieving revision 1.16 diff -u -r1.16 file.h --- include/asterisk/file.h 25 Feb 2004 22:31:50 -0000 1.16 +++ include/asterisk/file.h 10 Apr 2004 18:32:11 -0000 @@ -47,6 +47,7 @@ long (*tell)(struct ast_filestream *), struct ast_frame * (*read)(struct ast_filestream *, int *timetonext), void (*close)(struct ast_filestream *), + long (*length)(struct ast_filestream *), char * (*getcomment)(struct ast_filestream *)); //! Unregisters a file format @@ -262,6 +263,15 @@ */ int ast_stream_fastforward(struct ast_filestream *fs, long ms); +//! Gives the length of an audiofile +/*! + * \param chan channel to work with + * \param filename to use + * \param preflang prefered language to use + * Returns length, in samples, of an audiofile, or -1 if not implemented + */ +long ast_lengthfile(struct ast_channel *chan, char *filename, char *preflang); + //! Rewind stream ms /*! * \param ast_filestream fs filestream to act on Index: formats/format_ilbc.c =================================================================== RCS file: /usr/cvsroot/asterisk/formats/format_ilbc.c,v retrieving revision 1.3 diff -u -r1.3 format_ilbc.c --- formats/format_ilbc.c 1 May 2004 04:19:56 -0000 1.3 +++ formats/format_ilbc.c 1 May 2004 22:03:35 -0000 @@ -219,6 +219,7 @@ ilbc_tell, ilbc_read, ilbc_close, + NULL, ilbc_getcomment);